package com.sptpc.demo.controller;

import com.sptpc.demo.model.Student;
import com.sptpc.demo.service.IStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
@Slf4j
public class StudentController {
    @Autowired
    public IStudentService studentService;

    /**
     * 获取所有学生信息
     */
    @GetMapping("/")
    public List<Student> getStudents() {
        return studentService.findAll();
    }

    /**
     * 删除学生信息
     */
    @DeleteMapping("/{id}")
    public void delStudent(@PathVariable Long id) {
        log.info("删除学生id{}", id);
        studentService.delStudentByID(id);
    }

    /**
     * 添加学生信息
     */
    @PostMapping("/")
    public Student addStudent(@RequestBody Student student) {
        log.info("新增的学生对象{}", student);
        studentService.newStudent(student);
        return student;
    }
    /**
     * 修改学生信息
     */
    @PutMapping("/")
    public Student setStudent(@RequestBody Student student){
        log.info("修改的学生对象{}", student);
        studentService.upDataStudent(student);
        return student;
    }
}
